package com.sie.util;

import cn.hutool.core.util.ReUtil;
import com.sie.entity.ViewEmp;

public class RegularExpressionUtil {
    public static boolean empRegular(ViewEmp emp) {
        if (emp == null)
            return false;
        boolean loginName, name, phone, email, ps;
        if (emp.getLoginName() == null)
            return false;
        loginName = ReUtil.isMatch("^[A-Za-z0-9\\u4E00-\\u9FA5]{5,20}$", emp.getLoginName());
        if (emp.getEmpName() == null)
            return false;
        name = ReUtil.isMatch("^[A-Za-z0-9\\u4E00-\\u9FA5]{2,20}$", emp.getEmpName());
        if (emp.getEmpEmail() == null) {
            email = true;
        } else {
            email = ReUtil.isMatch("^[A-Za-z0-9\\u4e00-\\u9fa5]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$", emp.getEmpEmail());
        }
        if (emp.getEmpPhone() == null) {
            phone = true;
        } else {
            phone = ReUtil.isMatch("^1(3\\d|47|5((?!4)\\d)|7(0|1|[6-8])|8\\d)\\d{8,8}$", emp.getEmpPhone());
        }
        if (emp.getEmpPs() == null) {
            ps = true;
        } else {
            ps = ReUtil.isMatch("^[A-Za-z0-9_$\\u4E00-\\u9FA5]{0,500}$", emp.getEmpPs());
        }
        return loginName && name && phone && email && ps;
    }
}
